package egovframework.npqs.pqi.mobile;

import java.util.ArrayList;
import java.util.Stack;
import java.util.StringTokenizer;

import com.sds.BizAppLauncher.gov.aidl.GovController;
import com.sds.BizAppLauncher.gov.aidl.GovController.IGovCallback;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Application;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;
import egovframework.npqs.pqi.mobile.activity.LoginActivity;
import egovframework.npqs.pqi.mobile.jsoncontent.ApproveListItem;
import egovframework.npqs.pqi.mobile.jsoncontent.BuKipItem;
import egovframework.npqs.pqi.mobile.jsoncontent.DisinfectionResultDelayReceiveItem;
import egovframework.npqs.pqi.mobile.jsoncontent.DraftExamSerachItem;
import egovframework.npqs.pqi.mobile.jsoncontent.FruitPackingItem;
import egovframework.npqs.pqi.mobile.jsoncontent.LoginItem;
import egovframework.npqs.pqi.mobile.jsoncontent.PlaceOfficerItem;
import egovframework.npqs.pqi.mobile.jsoncontent.ProdResultItem;
import egovframework.npqs.pqi.mobile.jsoncontent.ProdSearchItem;
import egovframework.npqs.pqi.mobile.jsoncontent.QuarantineRequestItem;
import egovframework.npqs.pqi.mobile.jsoncontent.QuarantineResultItem;
import egovframework.npqs.pqi.mobile.jsoncontent.RelationDiseasePastItem;
import egovframework.npqs.pqi.mobile.jsoncontent.UrgencyLimitItem;
import egovframework.npqs.pqi.mobile.jsoncontent.listitem.ExportQuarantineResultListItem;
import egovframework.npqs.pqi.mobile.util.BrHttpManager;
import egovframework.npqs.pqi.mobile.util.BrUtilManager;
import egovframework.npqs.pqi.mobile.util.CameraUtil;
import egovframework.npqs.pqi.mobile.util.Navigation;

/**
 * @author choi
 *
 */
public class AppStatus extends Application{

	private static final String TAG = "AppStatus";
	public BrUtilManager utilm = null;
	public BrHttpManager httpm = null;
	public CameraUtil cameraUtil;
	public boolean quarantineState;
	public boolean finishState;
	private LoginItem loginItem;	// 로그인 정보
	private boolean dataLoadState;
	private boolean dataDetailLoadState;
	private boolean ableHome;
	public static Navigation navigation;
	public static String mUserId;
	public ProgressDialog dialog;
	private GovController controller;
	
	private ArrayList<ProdSearchItem> arrProdSearchItem;
	private ArrayList<ProdResultItem> arrProdResultItem;
	private ArrayList<ApproveListItem> arrApproveItem;
	private ArrayList<QuarantineResultItem> arrQuarantineStatusItem;	// 검역현황 목록
	private ArrayList<QuarantineRequestItem> arrQuarantineItem;			// 검역신청 목록
	private ArrayList<QuarantineResultItem> arrQuarantineResultItem;	// 검역결과 목록
	private ArrayList<DisinfectionResultDelayReceiveItem> arrDisinfectionItem;	// 소독결과 목록
	private ArrayList<DisinfectionResultDelayReceiveItem> arrDisinfectionStatusItem;	// 소독현황 목록
	private ArrayList<PlaceOfficerItem> arrPlaceOfficerItem;	// 현장검역관 목록
	private ArrayList<DraftExamSerachItem> arrDraftExamItem;	// 기안예문
	private ArrayList<RelationDiseasePastItem> arrRelationDeiseasePastItem; //관련병해충
	private ArrayList<UrgencyLimitItem> arrUrgencyLimitItem; //긴급제한, 수입금지
	private ArrayList<ExportQuarantineResultListItem> arrExportListItem;	//수출검역대기
	private ArrayList<BuKipItem> arrBuKipItem;	//부기사항
	private ArrayList<FruitPackingItem> arrFruitPackingItem;	//선과장

	@Override
	public void onCreate() {
		clearAppStatus();
		super.onCreate();
		utilm = BrUtilManager.getInstance();
	    httpm = BrHttpManager.getInstance();
	    cameraUtil = CameraUtil.getInstance();
	    navigation = new Navigation();
	}
	
	public void startBroker(Context context){
		controller = GovController.getInstance(context);
	}
	
	// 프로그레스 다이얼로그 함수
	public void showDialogNo(Context context) {
		Log.i("showDialogNo", "call in ...... "+context.toString());
		dialog = new ProgressDialog(context);
		dialog.setMessage(context.getApplicationContext().getString(R.string.data_load));
		dialog.setIndeterminate(true);
		dialog.setCancelable(false);
		dialog.show();
	}
	
	public boolean isAbleHome() {
		return ableHome;
	}
	
	public void setAbleHome(boolean ableHome) {
		if(ableHome==true){
			setDataLoadState(false);
			setDataDetailLoadState(false);
		}
		this.ableHome = ableHome;
	}

	public static String getmUserId() {
		return mUserId;
	}

	public static void setmUserId(String mUserId) {
		AppStatus.mUserId = mUserId;
	}

	public boolean isDataDetailLoadState() {
		return dataDetailLoadState;
	}

	public void setDataDetailLoadState(boolean dataDetailLoadState) {
		this.dataDetailLoadState = dataDetailLoadState;
	}

	public boolean isDataLoadState() {
		return dataLoadState;
	}

	public void setDataLoadState(boolean dataLoadState) {
		this.dataLoadState = dataLoadState;
	}

	public void clearAppStatus() {
		this.setFinishState(false);
		this.setQuarantineState(true);
	}
	
	public void appFinish(final Context context){
		new AlertDialog.Builder(context)
		.setTitle("종료")
		.setMessage("어플을 종료하시겠습니까??")
		.setPositiveButton("예", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				try {
					setFinishState(true);
					((Activity) context).finish();
				} catch (Exception e) {

				}
			}
		})
		.setNegativeButton("아니오", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				try {
					
				} catch (Exception e) {

				}
			}
		})
		.setCancelable(false)
		.show();
	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
	}

	@Override
	public void onTerminate() {
		super.onTerminate();
	}

	public LoginItem getLoginItem() {
		return loginItem;
	}

	public void setLoginItem(LoginItem loginItem) {
		this.loginItem = loginItem;
	}

	public ArrayList<QuarantineRequestItem> getArrQuarantineItem() {
		return arrQuarantineItem;
	}

	public void setArrQuarantineItem(
			ArrayList<QuarantineRequestItem> arrQuarantineItem) {
		this.arrQuarantineItem = arrQuarantineItem;
	}

	public boolean isQuarantineState() {
		return quarantineState;
	}

	public void setQuarantineState(boolean quarantineState) {
		this.quarantineState = quarantineState;
	}

	public ArrayList<DisinfectionResultDelayReceiveItem> getArrDisinfectionItem() {
		return arrDisinfectionItem;
	}

	public void setArrDisinfectionItem(
			ArrayList<DisinfectionResultDelayReceiveItem> arrDisinfectionItem) {
		this.arrDisinfectionItem = arrDisinfectionItem;
	}

	public ArrayList<QuarantineResultItem> getArrQuarantineResultItem() {
		return arrQuarantineResultItem;
	}

	public void setArrQuarantineResultItem(
			ArrayList<QuarantineResultItem> arrQuarantineResultItem) {
		this.arrQuarantineResultItem = arrQuarantineResultItem;
	}

	public ArrayList<QuarantineResultItem> getArrQuarantineStatusItem() {
		return arrQuarantineStatusItem;
	}

	public void setArrQuarantineStatusItem(
			ArrayList<QuarantineResultItem> arrQuarantineStatusItem) {
		this.arrQuarantineStatusItem = arrQuarantineStatusItem;
	}

	public ArrayList<DisinfectionResultDelayReceiveItem> getArrDisinfectionStatusItem() {
		return arrDisinfectionStatusItem;
	}

	public void setArrDisinfectionStatusItem(
			ArrayList<DisinfectionResultDelayReceiveItem> arrDisinfectionStatusItem) {
		this.arrDisinfectionStatusItem = arrDisinfectionStatusItem;
	}

	public ArrayList<ApproveListItem> getArrApproveItem() {
		return arrApproveItem;
	}

	public void setArrApproveItem(ArrayList<ApproveListItem> arrApproveItem) {
		this.arrApproveItem = arrApproveItem;
	}

	public ArrayList<ProdResultItem> getArrProdResultItem() {
		return arrProdResultItem;
	}

	public void setArrProdResultItem(ArrayList<ProdResultItem> arrProdResultItem) {
		this.arrProdResultItem = arrProdResultItem;
	}

	public ArrayList<ProdSearchItem> getArrProdSearchItem() {
		return arrProdSearchItem;
	}

	public void setArrProdSearchItem(ArrayList<ProdSearchItem> arrProdSearchItem) {
		this.arrProdSearchItem = arrProdSearchItem;
	}

	public ArrayList<PlaceOfficerItem> getArrPlaceOfficerItem() {
		return arrPlaceOfficerItem;
	}

	public void setArrPlaceOfficerItem(ArrayList<PlaceOfficerItem> arrPlaceOfficerItem) {
		this.arrPlaceOfficerItem = arrPlaceOfficerItem;
	}

	public ArrayList<DraftExamSerachItem> getArrDraftExamItem() {
		return arrDraftExamItem;
	}

	public void setArrDraftExamItem(ArrayList<DraftExamSerachItem> arrDraftExamItem) {
		this.arrDraftExamItem = arrDraftExamItem;
	}

	public ArrayList<RelationDiseasePastItem> getArrRelationDeiseasePastItem() {
		return arrRelationDeiseasePastItem;
	}

	public void setArrRelationDeiseasePastItem(
			ArrayList<RelationDiseasePastItem> arrRelationDeiseasePastItem) {
		this.arrRelationDeiseasePastItem = arrRelationDeiseasePastItem;
	}

	public ArrayList<UrgencyLimitItem> getArrUrgencyLimitItem() {
		return arrUrgencyLimitItem;
	}

	public void setArrUrgencyLimitItem(
			ArrayList<UrgencyLimitItem> arrUrgencyLimitItem) {
		this.arrUrgencyLimitItem = arrUrgencyLimitItem;
	}

	public boolean isFinishState() {
		return finishState;
	}

	public void setFinishState(boolean finishState) {
		this.finishState = finishState;
	}

	public ArrayList<ExportQuarantineResultListItem> getArrExportListItem() {
		return arrExportListItem;
	}

	public void setArrExportListItem(
			ArrayList<ExportQuarantineResultListItem> arrExportListItem) {
		this.arrExportListItem = arrExportListItem;
	}

	public ArrayList<BuKipItem> getArrBuKipItem() {
		return arrBuKipItem;
	}

	public void setArrBuKipItem(ArrayList<BuKipItem> arrBuKipItem) {
		this.arrBuKipItem = arrBuKipItem;
	}

	public ArrayList<FruitPackingItem> getArrFruitPackingItem() {
		return arrFruitPackingItem;
	}

	public void setArrFruitPackingItem(
			ArrayList<FruitPackingItem> arrFruitPackingItem) {
		this.arrFruitPackingItem = arrFruitPackingItem;
	}

}
